﻿using MediatR;
using T_settlement.API.Application.Command.OutputCommand;
using T_settlement.Infrastructure.Impl;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.OutputCommandHandlers
{
    public class PDelOutputCommandHandlers:IRequestHandler<PDelOutputCommand,int>
    {
        private readonly IOutputRepository outputRepository;

        public PDelOutputCommandHandlers(IOutputRepository outputRepository)
        {
            this.outputRepository = outputRepository;
        }

        public async Task<int> Handle(PDelOutputCommand request, CancellationToken cancellationToken)
        {
            var Id = request.OutputId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await outputRepository.GetAsync(x => Id.Contains(x.OutputId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await outputRepository.UpdateAsyncRange(list);
        }
    }
}
